#pragma once
#include<iostream>
#include"protocol.hpp"
using namespace std;
class serveror
{

public:
serveror()
{
}
~serveror()
{
}
Response calculatorhelper(const Request st)
{

   Response res(0,0);
   switch(st.op)
   {
    case '+':
        res.result=st.x+st.y;
        break;

    case '-':
        res.result=st.x-st.y;
        break;
    case '*':
        res.result=st.x*st.y;
        break;
    case '/':
         {
          if(st.y==0)res.code=1;
          else   res.result=st.x/st.y;
          
         }
         break;
    case '%':
         {
          if(st.y==0)res.code=2;
          else   res.result=st.x%st.y;
         }
         break;

   }

   return  res;

}
string calculator(string &package)
{

string content;
bool r=decode(package,&content);   //"9 + 10"
if(!r)return "";

Request st;
r=st.Deserialize(content);
if(!r)return "";


content="";
Response ret=calculatorhelper(st);
ret.Serialize(&content);
content=encode(content);
return content;

}


};
